package org.openstreetmap.gui.jmapviewer;

//License: GPL. Copyright 2008 by Jan Peter Stotz

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;

import org.openstreetmap.gui.jmapviewer.interfaces.MapMarker;

/**
 * A simple implementation of the {@link MapMarker} interface. Each map marker
 * is painted as a circle with a black border line and filled with a specified
 * color.
 *
 * @author Jan Peter Stotz
 *
 */
public class PetitBateau implements MapMarker {

    double lat;
    double lon;
    Color color;
    String allure;
    double angle;
    double vitesse;
    
    public PetitBateau() { }
    
    public PetitBateau(double lat, double lon) {
        this(Color.YELLOW, lat, lon);
    }

    public PetitBateau(Color color, double lat, double lon) {
        super();
        this.color = color;
        this.lat = lat;
        this.lon = lon;
    }
    
    public PetitBateau(double lat, double lon, String allure, double angle, double vitesse) {
    	super();
    	this.lat = lat;
    	this.lon = lon;
    	this.allure = allure;
    	this.angle = angle;
    	this.vitesse = vitesse;
    }

    public double getLat() {
        return lat;
    }

    public double getLon() {
        return lon;
    }
    
    public double getAngle() {
    	return angle;
    }
    
    public String getAllure() {
    	return allure;
    }
    
    public double getVitesse() {
    	return vitesse;
    }
    
    public void setLat(double lat) {
    	this.lat = lat;
    }

    public void setLon(double lon) {
    	this.lon = lon;
    }
    
    public void setAngle(double angle) {
    	this.angle = angle;
    }
    
    public void setAllure(String allure) {
    	this.allure = allure;
    }
    
    public void setVitesse(double vitesse) {
    	this.vitesse = vitesse;
    }
    
    public void lever_ancre() {
    	this.allure = "en marche";
    }
    
    public void jeter_ancre() {
    	this.allure = "arret";
    }
    
    public void tourner_gauche() {
    	if(this.angle + 90 > 360){
    		this.angle = this.angle - 270;
    	} else {
    		this.angle = this.angle + 90;
    	}
    }
    
    public void tourner_droite() {
    	if(this.angle - 90 < 0){
    		this.angle = this.angle + 270;
    	} else {
    		this.angle = this.angle - 90;
    	}
    }
    
    public void avancer() {
    	
    	double ang = angle;
    	double x, y, dist_x, dist_y;
    	double radian = Math.toRadians(ang);
    	
    	x = Math.cos(radian);
    	y = Math.sin(radian);
    	
    	dist_x = (vitesse * x) / 100000;
    	dist_y = (vitesse * y) / 100000;
    	
    	this.setLon(this.getLon() + dist_x);
    	this.setLat(this.getLat() + dist_y);
    	
    	//System.err.println(ang + " _ " + x + " _ " + y);
    }
    
    public void modifier_vitesse(double a) {
    	this.vitesse = this.vitesse + a;
    }
    
    public void paint(Graphics g, Point position) {
        int size_h = 5;
        int size = size_h * 2;
        Toolkit kit = Toolkit.getDefaultToolkit();
        Image img = null;
        
		try {
			img = ImageIO.read(new File("images/trimaran_modele.png"));
			
		} catch (IOException e) {
			e.printStackTrace();
		}
		
        g.drawImage(img, position.x - size, position.y - size_h, 75, 75, null);
        
    }

    @Override
    public String toString() {
        return "MapMarker at " + lat + " " + lon;
    }

}









